//2009/08/17 19:33:10
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class IsingModel
{
public:
    int energy(vector <string> spins)
    {
		int ret = 0;
		for(int i=0; i<spins.size(); i++)
			for(int j=1; j<spins[i].size(); j++)
				if(spins[i][j] == spins[i][j-1]) ret --;
				else ret ++;
		for(int i=0; i<spins[0].size(); i++)
			for(int j=1; j<spins.size(); j++)
				if(spins[j][i] == spins[j-1][i]) ret --;
				else ret ++;
		return ret;
    }
};
